package com.beta.elephant.vo;

import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.io.Serializable;

/**
 * 列表分页查询响应
 */
@Data
public class BaseListResp extends BaseResp implements Serializable {
    @ApiModelProperty(value = "当前页数，从1开始")
    public int pageNo;
    @ApiModelProperty(value = "每页记录数，默认20")
    public int pageSize;
    @ApiModelProperty(value = "总记录数")
    private int totalRecord;

    public int getTotalPage() {
        if (pageNo < 1) {
            pageNo = 1;
        }
        if (pageSize < 1) {
            pageSize = 20;
        }
        if (totalRecord < 1) {
            return 0;//如果总数不正常，则返回0
        }
        int page = totalRecord / pageSize;
        return totalRecord % pageSize > 0 ? (page + 1) : page;
    }
}
